// apply

// ES 5
Function.prototype.myApply = function (context, arr) {
  if (typeof this !== 'function') {
    throw 'caller must be a function'
  }
  
  context = context || window
  
  context.fn = this

  var res
  if (!arr) {
    res = context.fn()
  } else {
    var args = []
    for (var i=0; i<arr.length; ++i) {
      args.push( 'arr[' + i + ']' )
    }
    res = eval('context.fn(' + args + ')')
  }
  delete context.fn

  return res
}


// ES 6
Function.prototype.myApply = function (context=window, arr) {
  if (typeof this !== 'function') {
    throw 'caller must be a function'
  }

  const fn = Symbol()

  context.fn = this

  let res = context.fn(...arr)

  delete context.fn

  return res
}